package com.ebelter.ty.ui.activity;


import android.app.Dialog;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.models.eventbus.CommonEventBus;
import com.ebelter.btcomlib.utils.SpUtil;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.views.dialogs.TextTipDialog;
import com.ebelter.ty.AppConfig;
import com.ebelter.ty.R;
import com.ebelter.ty.ui.fragment.scale.Scale_M_B5_Fragment;

import org.greenrobot.eventbus.EventBus;



public class DeviceManagerActivity extends BaseActivity implements View.OnClickListener {




    ImageView back_iv;


    TextView devicemanager_mac_address_tv;



    TextView modify_done_tv;


    @Override
    protected int loadLayoutById() {
        return R.layout.devicemaneger_ly;
    }




    @Override
    protected void initData() {
        devicemanager_mac_address_tv = findViewById(R.id.devicemanager_mac_address_tv);
        modify_done_tv = findViewById(R.id.modify_done_tv);
        back_iv = findViewById(R.id.modify_back_bt);
        back_iv.setOnClickListener(this);
        devicemanager_mac_address_tv.setOnClickListener(this);
        modify_done_tv.setOnClickListener(this);
        String mac= SpUtil.readString(AppConfig.DEVICE_MAC);
        //String name=SpUtil.readString(AppConfig.DEVICE_Name);
        devicemanager_mac_address_tv.setText(StringUtils.getResStr(R.string.scalename_name)+" ("+mac+")");

    }




    private void showTipDialog() {

        TextTipDialog textTipDialog=new TextTipDialog(this, StringUtils.getResStr(R.string.device_management_remove_tip));
        textTipDialog.setListener(new TextTipDialog.ICancelOkBtListener() {
            @Override
            public void cancel(Dialog dialogView) {
                dialogView.cancel();
            }

            @Override
            public void ok(Dialog dialogView) {
                SpUtil.writeString(AppConfig.DEVICE_MAC,null);
               // SpUtil.writeString(AppConfig.DEVICE_Name,null);
                devicemanager_mac_address_tv.setText("");
                dialogView.cancel();
                CommonEventBus eventBus=new CommonEventBus("DeviceManagerActivity", Scale_M_B5_Fragment.TAG,3,null);
                EventBus.getDefault().post(eventBus);
                finish();//直接退出
            }
        });
        textTipDialog.show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.modify_back_bt:
                finish();
                break;
            case R.id.modify_done_tv://绑定提示界面现在绑定按钮
                showTipDialog();
                break;


        }
    }
}
